from django.shortcuts import render, redirect
from app01 import models
from functools import wraps
from django.contrib import auth

# Create your views here.


def login(request):
    if request.method == "POST":
        username = request.POST.get('username')
        pwd = request.POST.get('password')
        user = auth.authenticate(username=username, password=pwd)
        auth.login(request, user)
        if user:
            return redirect('/app01/index')
    return render(request, 'login4.html')


def logout(request):
    auth.logout(request)
    return redirect('/app01/login4')


def index(request):
    print(request.user.username)
    return render(request, 'index4.html')


def home(request):
    return render(request, 'login4.html')
